package com.wxyzz.satserver.comment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wxyzz.common.core.entity.User;
import com.wxyzz.satserver.comment.VO.CommentVO;
import com.wxyzz.satserver.comment.dao.CommentDao;
import com.wxyzz.satserver.comment.entity.Comment;
import com.wxyzz.satserver.comment.service.CommentService;
import com.wxyzz.satserver.user.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * --- 加油，努力 ---
 *
 * @Author XYP
 * @Date 2024/11/16
 * @Solgne 从想做到能做
 * @Desc
 */
@Service
public class CommentServiceImpl implements CommentService {

    @Resource
    private CommentDao commentDao;

    @Resource
    private UserService userService;

    @Override
    public List<CommentVO> selectArticleComments(Integer aid) {
        List<Comment> comments = commentDao.selectList(new LambdaQueryWrapper<Comment>()
                .eq(Comment::getAid, aid));
        List<CommentVO> articleCommonts = comments.stream().map(item -> {
            CommentVO commentVO = new CommentVO();
            BeanUtils.copyProperties(item, commentVO);

            User user = userService.selectById(item.getUidComment());
            commentVO.setAvater(user.getAvatar());
            commentVO.setNickName(user.getNickname());

            return commentVO;
        }).collect(Collectors.toList());

        return articleCommonts;
    }
}
